#include "dominion.h"
#include "rngs.h"
#include "dominion_helpers.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>

int main (int argc, char **argv)
{
	int testVariable;
	int bonus = 0;
	struct gameState *test = newGame();
	//set number of players to 2
	test->numPlayers = 2;
	//set handcount to be 5
	test->handCount[1] = 5;
	test->handCount[0] = 5;
	printf("handCount player1: %d\n", test->handCount[0]);
	printf("handCount player2: %d\n", test->handCount[1]);
	
	//add five copper cards to hand
	test->hand[1][0] = copper;
	test->hand[1][1] = copper;
	test->hand[1][2] = copper;
	test->hand[1][3] = copper;
	test->hand[1][4] = copper;
	
	//call update coins player1, 5 coppers, no bonus, coins should == 5
	updateCoins(1, test, bonus);
	testVariable = test->coins;
	if (testVariable == 5)
		printf("Test passed.\n");
	else
		printf("%d\n", testVariable);
	
	//add five silver cards to hand	
	test->hand[1][0] = silver;
	test->hand[1][1] = silver;
	test->hand[1][2] = silver;
	test->hand[1][3] = silver;
	test->hand[1][4] = silver;
	
	//call update coins player1, 5 silver, no bonus, coins should == 10
	updateCoins(1, test, bonus);
	testVariable = test->coins;
	if (testVariable == 10)
		printf("Test passed.\n");
		
	//add five gold cards to hand	
	test->hand[1][0] = gold;
	test->hand[1][1] = gold;
	test->hand[1][2] = gold;
	test->hand[1][3] = gold;
	test->hand[1][4] = gold;
	
	//call update coins player1, 5 gold, no bonus, coins should == 15
	updateCoins(1, test, bonus);
	testVariable = test->coins;
	if (testVariable == 15)
		printf("Test passed.\n");
		
	//reset values
	test->hand[0][0] = 0;
	test->hand[0][1] = 0;
	test->hand[0][2] = 0;
	test->hand[0][3] = 0;
	test->hand[0][4] = 0;
	test->hand[1][0] = 0;
	test->hand[1][1] = 0;
	test->hand[1][2] = 0;
	test->hand[1][3] = 0;
	test->hand[1][4] = 0;
	
	//make sure values are reset
	assert(test->hand[0][0] == 0);
	assert(test->hand[0][1] == 0);
	assert(test->hand[0][2] == 0);
	assert(test->hand[0][3] == 0);
	assert(test->hand[0][4] == 0);
	assert(test->hand[1][0] == 0);
	assert(test->hand[1][1] == 0);
	assert(test->hand[1][2] == 0);
	assert(test->hand[1][3] == 0);
	assert(test->hand[1][4] == 0);
	
	//xtra tests
	
	test->hand[0][0] = gold;
	test->hand[0][1] = silver;
	test->hand[0][4] = copper;
	test->hand[1][0] = gold;
	test->hand[1][1] = silver;
	test->hand[1][4] = copper;
	
	//call update coins player1 & player 2, 6 coins per player
	updateCoins(0, test, bonus);
	testVariable = test->coins;
	if (testVariable == 6)
		printf("Test passed.\n");
	else 
		printf("variable: %d\n", testVariable);
		
	updateCoins(1, test, bonus);
	testVariable = test->coins;
	if (testVariable == 6)
		printf("Test passed.\n");
	else 
		printf("variable: %d\n", testVariable);
		
	//reset values
	test->hand[0][0] = 0;
	test->hand[0][1] = 0;
	test->hand[0][2] = 0;
	test->hand[0][3] = 0;
	test->hand[0][4] = 0;
	test->hand[1][0] = 0;
	test->hand[1][1] = 0;
	test->hand[1][2] = 0;
	test->hand[1][3] = 0;
	test->hand[1][4] = 0;
	
	//make sure values are reset
	assert(test->hand[0][0] == 0);
	assert(test->hand[0][1] == 0);
	assert(test->hand[0][2] == 0);
	assert(test->hand[0][3] == 0);
	assert(test->hand[0][4] == 0);
	assert(test->hand[1][0] == 0);
	assert(test->hand[1][1] == 0);
	assert(test->hand[1][2] == 0);
	assert(test->hand[1][3] == 0);
	assert(test->hand[1][4] == 0);
		
	//test bonus
	bonus = 2;
	updateCoins(1, test, bonus);
	testVariable = test->coins;
	if(testVariable == 2)
		printf("Test passed.\n");
	else
		printf("variable: %d\n", testVariable);
	
	bonus = 20;
	updateCoins(1, test, bonus);
	testVariable = test->coins;
	if(testVariable == 20)
		printf("Test passed.\n");
	else
		printf("variable: %d\n", testVariable);
		
	bonus = 200;
	updateCoins(1, test, bonus);
	testVariable = test->coins;
	if(testVariable == 200)
		printf("Test passed.\n");
	else
		printf("variable: %d\n", testVariable);
	
	//not sure if the bonus should be able to take negative values
	bonus = -3;
	updateCoins(1, test, bonus);
	testVariable = test->coins;
	if(testVariable == -3)
		printf("Test passed.\n");
	else
		printf("variable: %d\n", testVariable);
		
	return 0;
}
